package wqh.global;



import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import wqh.websocket.alarm.AlarmSocketHandler;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SessionListener implements HttpSessionListener{


    public void sessionCreated(HttpSessionEvent se)
    {
      System.out.println("超时时间/秒：" + se.getSession().getMaxInactiveInterval());
    }

    public void sessionDestroyed(HttpSessionEvent se)
    {
        String user = GlobalSession.removeSessionBySessionIDGetName(se.getSession().getId());

        ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:/spring/spring-beans.xml");
        AlarmSocketHandler alarmSocketHandler = (AlarmSocketHandler) ac.getBean("alarmSocketHandler") ;
        alarmSocketHandler.sendLogOutToWeb(se.getSession().getId());

        System.out.println("用户超时下线：" + user +":" + se.getSession().getId());
    }
}
